package main

import (
	"time"
	"yunque-message-client/model/ProtoModel"
	"yunque-message-client/service"
)

/**
 * @Description
 * @Author yichen
 * @Date 2023/9/24 0024 14:07
 **/

type reply struct {
}
type message struct {
}

// 回复体
func (*reply) replybody() *ProtoModel.ReplyBodyProto {
	msg := &ProtoModel.ReplyBodyProto{}
	msg.Code = "200"
	msg.Key = "1234546"
	msg.Data = map[string]string{"text": "你好，这是一条消息"}
	msg.Timestamp = time.Now().Unix()
	return msg
}

// 消息体
func (*message) message() *ProtoModel.MessageProto {
	msg := &ProtoModel.MessageProto{}
	msg.Id = 1
	msg.Receiver = "1074"
	msg.Sender = "1078"
	msg.Content = map[string]string{"text": "你好，这是一条消息"}
	msg.SendTime = time.Now().Unix()
	return msg
}

// 推送给指定用户消息
func (this *message) sendToUid() {
	msgservice := &service.Message{}
	msgs := []*ProtoModel.MessageProto{this.message()}
	uid := "1074"
	err := msgservice.SendToUid(uid, msgs)
	if err != nil {
		return
	}

}

// 推送给指定用户消息
func (this *message) sendToUidDid() {
	msgservice := &service.Message{}
	msgs := []*ProtoModel.MessageProto{this.message()}
	uid := "1074"
	did := "h5"
	err := msgservice.SendToDid(uid, did, msgs)
	if err != nil {
		return
	}

}

// 推送给指定用户消息
func (this *message) sendToAll() {
	msgservice := &service.Message{}

	msgs := []*ProtoModel.MessageProto{this.message()}
	err := msgservice.SendToAll(msgs)
	if err != nil {
		return
	}

}

// 遍历推送给读消息用户
func (this *message) sendToList() {
	msgservice := &service.Message{}
	msgs := []*ProtoModel.MessageProto{this.message()}
	err := msgservice.SendList(msgs)
	if err != nil {
		return
	}

}

// 遍历推送给读请求的用户
func (this *reply) sendToList() {
	msgservice := &service.ReplyBody{}
	msgs := []*ProtoModel.ReplyBodyProto{this.replybody()}
	err := msgservice.SendList(msgs)
	if err != nil {
		return
	}

}

func main() {
	//sendToUid()
	//推送请求信息 使用示例
	replyService := &reply{}
	//遍历推送给读取人
	replyService.sendToList()
	//	更多方法 参考推消息示例。接口一样

	//	推送消息使用示例
	//推送请求信息 使用示例
	messageService := &message{}
	//遍历推送消息给读取人
	messageService.sendToList()
	//推送消息给指定用户的 某个设备
	messageService.sendToUidDid()
	//遍历消息给指定用户
	messageService.sendToUid()
	//遍历消息给所有人
	messageService.sendToAll()

}
